//
//  changeUserViewController.m
//  giuseppe
//
//  Created by Apple on 15/8/12.
//  Copyright (c) 2015年 GiantUmbrella. All rights reserved.
//

#import "changeUserViewController.h"
#import "loginViewController.h"
#import "userManager.h"

@interface changeUserViewController ()<UITableViewDataSource,UITableViewDelegate>{
    UITableView *_tableView;
}

@end

@implementation changeUserViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    
    //自定义的导航栏
    UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 64)];
    navView.backgroundColor = baseColor;
    navView.alpha = 0.90;
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(10, 33, 27, 16);
    [backButton setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth/2-50, 20, 100, 40)];
    titleLabel.text = @"切换账户";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
//    UIButton *changeUserButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [changeUserButton setTitle:@"添加账户" forState:UIControlStateNormal];
//    changeUserButton.frame = CGRectMake(kScreenWidth-80, 20, 80, 40);
//    [changeUserButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    changeUserButton.titleLabel.font = [UIFont systemFontOfSize:13];
//    [changeUserButton addTarget:self action:@selector(addUser) forControlEvents:UIControlEventTouchUpInside];
    

    [navView addSubview:backButton];
    [navView addSubview:titleLabel];
//    [navView addSubview:changeUserButton];
    
    [self.view addSubview:navView];
    
    [self _initTableView];
}

- (void)_initTableView{
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, kScreenWidth, kScreenHeight)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    _tableView.rowHeight = 80;
    
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-_tableView.rowHeight*2)];
    footerView.backgroundColor = [UIColor whiteColor];
    
    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [addButton setTitle:@"添加账户" forState:UIControlStateNormal];
    [addButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    addButton.frame = CGRectMake(kScreenWidth/2-50, kScreenHeight-160-160, 100, 30);
    [addButton addTarget:self action:@selector(addUser) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:addButton];
    
    _tableView.tableFooterView = footerView;
    
    
    [self.view addSubview:_tableView];
    
}

#pragma mark - Table view data source && delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [userManager shardInfo].userArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    
    
    NSString *labelText = [[userManager shardInfo].userArray[indexPath.row] objectForKey:@"studentName"];
    cell.textLabel.text = labelText;
    return cell;
}

//设置点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    
    
    
}



- (void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)addUser{
    
    loginViewController *loginVC = [[loginViewController alloc]init];
//    loginVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//    [self presentViewController: loginVC animated:YES completion:NULL];
    [self.navigationController pushViewController:loginVC animated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
